<template>
    <div>
        <h2>门店添加</h2>
        <table class="table table-bordered">
            <tbody>
                <tr>
                <td align="right">门店名称</td>
                <td>
                    <input type="text" v-model="info.ShopName"></input>
                </td>
            </tr>
            <tr>
                <td align="right">分店名称</td>
                <td>
                    <input type="text" v-model="info.BranchName"></input>
                </td>
            </tr>
            <tr>
                <td align="right">门店地址</td>
                <td>
                    <select v-model="info.AddressName">
                        <option value="">请选择</option>
                        <option value="北京">北京</option>
                        <option value="天津">天津</option>
                        <option value="河北">河北</option>
                        <option value="河南">河南</option>
                        <option value="山东">山东</option>
                        <option value="山西">山西</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td align="right">门店图片</td>
                <td>
                    <input type="file" ></input>
                </td>
            </tr>
            <tr>
                <td align="right">联系电话</td>
                <td>
                    <input type="text" v-model="info.Phone" maxlength="11"></input>
                </td>
            </tr>
            <tr>
                <td align="right">门店介绍</td>
                <td>
                    <textarea rows="4" cols="40" v-model="info.Decs"></textarea>
                </td>
            </tr>
            <tr>
                <td align="right">入店须知</td>
                <td>
                    <textarea rows="4" cols="40" v-model="info.Inton"></textarea>
                </td>
            </tr>
            <tr>
                <td align="right"></td>
                <td>
                    <input type="button" value="确定" class="btn btn-primary" @click="ok"></input>
                </td>
            </tr>
            </tbody>
            
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted} from 'vue'
import {useRouter,useRoute} from 'vue-router'
import axios from 'axios';
import moment from 'moment';

const router = useRouter()
const route = useRoute()

let info:any = reactive({   
  ShopName: '',
  BranchName: '',
  AddressName:'',
  Phone: '',
  Decs: '',
  Inton: ''
});

const ok=()=>{
    if(info.ShopName==''){
        alert('门店名称不能为空');
        return;
    }
    if(info.BranchName==''){
        alert('分店名称不能为空');
        return;
    }
    if(info.AddressName==''){
        alert('请选择地址');
        return;
    }
    if(info.Phone==''){
        alert('练习电话不能为空');
        return;
    }
    if(info.Decs==''){
        alert('门店介绍不能为空');
        return;
    }
    if(info.Inton==''){
        alert('入店须知不能为空');
        return;
    }
    axios({
        url:'/api/Shops/AddShop',
        method:'post',
        data:info
    })
    .then((res)=>{
        console.log(res);
        if(res.data==-1){
            alert('已有该门店 请重新添加');
            return;
        }
        if(res.data>0){
            alert('添加成功');
            router.push('/shopList');
            return;
        }
        alert('添加失败');
        return;
    })
    .catch((err)=>{
        console.log(err)
    })
}
</script>

<style scoped>

</style>